package com.saihai.jiankang.ufYsgl.controller;

import com.saihai.common.annotation.Log;
import com.saihai.common.core.controller.BaseController;
import com.saihai.common.core.domain.AjaxResult;
import com.saihai.common.core.page.TableDataInfo;
import com.saihai.common.enums.BusinessType;
import com.saihai.common.utils.poi.ExcelUtil;
import com.saihai.jiankang.ufYsgl.domain.UfYsgl;
import com.saihai.jiankang.ufYsgl.service.IUfYsglService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Predicate;
import java.util.stream.Collectors;

/**
 * 医生Controller
 * 
 * @author hzn
 * @date 2024-07-05
 */
@RestController
@RequestMapping("/jiankang/ufYsgl")
public class UfYsglController extends BaseController
{
    @Autowired
    private IUfYsglService ufYsglService;

    /**
     * 查询医生列表
     */
    @GetMapping("/list")
    public TableDataInfo list(UfYsgl ufYsgl)
    {
        startPage();
        List<UfYsgl> list = ufYsglService.selectUfYsglList(ufYsgl);
        return getDataTable(list);
    }


    /**
     * 查询医生的类目
     */
    @GetMapping("/selectDoctorType/{id}")
    public AjaxResult selectYsLm(@PathVariable("id") Long id) {
        // 创建List并添加Map
        List<Map<String, String>> listOfMaps = new ArrayList<>();
        UfYsgl ufYsgl = ufYsglService.selectUfYsglById(id);
        /****** 内科类型****/
        Map map_nk = new HashMap();
        if (ufYsgl.getNk().equals("1")) {
            map_nk.put("key","nk");
            map_nk.put("label","内科");
            if (ufYsgl.getXin().equals("1")) {

                map_nk.put("xin","心");
            }
            if (ufYsgl.getGan().equals("1")) {
                map_nk.put("gan","肝");
            }
            if (ufYsgl.getPi().equals("1")) {
                map_nk.put("pi","脾");
            }
            if (ufYsgl.getXy().equals("1")) {
                map_nk.put("xy","血压");
            }
            if (ufYsgl.getFhl().equals("1")) {
                map_nk.put("fhl","肺活量");
            }
            if (ufYsgl.getFb().equals("1")) {
                map_nk.put("fb","腹部");
            }
            if (ufYsgl.getNkqt().equals("1")) {
                map_nk.put("nkqt","内科其他");
            }
            if (ufYsgl.getJbs().equals("1")) {
                map_nk.put("jbs","疾病史");
            }
            listOfMaps.add(map_nk);
        }
        /************ 外科类型  **********************/
        if (ufYsgl.getWk().equals("1")) {
            Map map_wk = new HashMap();
            map_wk.put("key","wk");
            map_wk.put("label","外科");
            if (ufYsgl.getTb().equals("1")) {
                map_wk.put("tb","头部");
            }
            if (ufYsgl.getJb().equals("1")) {
                map_wk.put("jb","颈部");
            }
            if (ufYsgl.getXb().equals("1")) {
                map_wk.put("xb","胸部");
            }
            if (ufYsgl.getJz().equals("1")) {
                map_wk.put("jz","脊柱");
            }
            if (ufYsgl.getSz().equals("1")) {
                map_wk.put("sz","四肢");
            }
            if (ufYsgl.getPf().equals("1")) {
                map_wk.put("pf","皮肤");
            }
            if (ufYsgl.getLbj().equals("1")) {
                map_wk.put("lbj","淋巴结");
            }
            if (ufYsgl.getWkqt().equals("1")) {
                map_wk.put("wkqt","外科其他");
            }
            listOfMaps.add(map_wk);
        }
        /************* 耳鼻喉科  ********************/
        if(ufYsgl.getEbhk().equals("1")){
            Map map_ebhk = new HashMap();
            map_ebhk.put("key","ebhk");
            map_ebhk.put("label","耳鼻喉科");
            listOfMaps.add(map_ebhk);
        }
        /************* 眼科  ********************/
        if(ufYsgl.getYk().equals("1")){
            Map map_yk = new HashMap();
            map_yk.put("key","yk");
            map_yk.put("label","眼科");
            listOfMaps.add(map_yk);
        }
        /************* 口腔科  ********************/
        if(ufYsgl.getKqk().equals("1")){
            Map map_kqk = new HashMap();
            map_kqk.put("key","kqk");
            map_kqk.put("label","口腔科");
            listOfMaps.add(map_kqk);
        }
        /************* 实验室  ********************/
        if(ufYsgl.getSys().equals("1")){
            Map map_kqk = new HashMap();
            map_kqk.put("key","sys");
            map_kqk.put("label","实验室");
            listOfMaps.add(map_kqk);
        }
        /************* 实验室  ********************/
        if(ufYsgl.getXtzb().equals("1")){
            Map map_kqk = new HashMap();
            map_kqk.put("key","xtzb");
            map_kqk.put("label","形态指标");
            listOfMaps.add(map_kqk);
        }
        return AjaxResult.success(listOfMaps);
    }



    /**
     * 导出医生列表
     */
    @Log(title = "医生", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UfYsgl ufYsgl)
    {
        List<UfYsgl> list = ufYsglService.selectUfYsglList(ufYsgl);
        ExcelUtil<UfYsgl> util = new ExcelUtil<UfYsgl>(UfYsgl.class);
        util.exportExcel(response, list, "医生数据");
    }

    /**
     * 获取医生详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(ufYsglService.selectUfYsglById(id));
    }

    /**
     * 新增医生
     */
    @Log(title = "医生", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UfYsgl ufYsgl)
    {
        return toAjax(ufYsglService.insertUfYsgl(ufYsgl));
    }

    /**
     * 修改医生
     */
    @Log(title = "医生", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UfYsgl ufYsgl)
    {
        return toAjax(ufYsglService.updateUfYsgl(ufYsgl));
    }

    /**
     * 删除医生
     */
    @Log(title = "医生", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ufYsglService.deleteUfYsglByIds(ids));
    }
}
